package momo.multitree.simulation.decentralized;

import java.io.FileReader;

import momo.multitree.simulation.SimulationFrameWork;
import momo.multitree.simulation.SimulationWorker;
import momo.multitree.structure.Graph;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SimulationDecentFrameWork
{
	private Log log = LogFactory.getLog(SimulationDecentFrameWork.class);
	
	//used to test one file
	private String[] filenames;// = {"15_node_symmetric_dataset_1.txt"};
	
	public SimulationDecentFrameWork()
	{
		//uncomment the codes below to run multiple cases
		int start_range = 0;
		int size_per_test = 100;
		
//		filenames = new String[size_per_test];
//		for(int i=0; i<filenames.length; i++)
//		{
//			filenames[i] = "9_node_symmetric_dataset_" + (i+1+start_range) +".txt";
//		}
		
		//uncomment the codes below to run all test
		filenames = new String[500];
		int counter = 1;
		for(int i=0; i<filenames.length; i++)
		{
			if ( i < 100 )
				filenames[i] = "5_node_symmetric_dataset_" + counter +".txt";
			else if ( i < 200 )
				filenames[i] = "6_node_symmetric_dataset_" + counter +".txt";
			else if ( i < 300 )
				filenames[i] = "7_node_symmetric_dataset_" + counter +".txt";
			else if ( i < 400 )
				filenames[i] = "8_node_symmetric_dataset_" + counter +".txt";
			else if ( i < 500 )
				filenames[i] = "9_node_symmetric_dataset_" + counter +".txt";
			
			counter ++;
			if ( counter > 100 )
				counter = 1;
				
		}
	}
	
	public void run()
	{
		for(String filename: filenames)
		{
			try
			{
				Graph g = new Graph(new FileReader("dataset/"+filename));
				
				SimulationDecentWorker worker = new SimulationDecentWorker(g);
				
				log.info(filename+", " + worker.run());
			}catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String args[])
	{
		SimulationDecentFrameWork app = new SimulationDecentFrameWork();
		app.run();
	}
}//end of class SimulationDecentFrameWork
